package com.ohc.小码哥.第二季.排序;

/**
 * @Author 欧皓辰
 * @Date 2021/12/22 22:03
 * @Version 1.0
 */
public abstract class Sort {
    private Integer[] array;
    private int cmpCount;
    private int swapCount;
    private long time;

    public void sort(Integer[] array) {
        if (array == null || array.length < 2) return;
        this.array = array;
        long begin = System.currentTimeMillis();
        sort();
        time = System.currentTimeMillis() - begin;
    }

    protected abstract void sort();

    /**
     * 返回值等于0  arr[o1] == arr[i2]
     * 返回值大于0   arr[i1]  大
     *
     * @param i1
     * @param i2
     * @return
     */
    protected int cmp(int i1, int i2) {
        return array[i1] - array[i2];
    }

    protected int cmpElement(Integer v1, Integer v2) {
        cmpCount++;
        return v1 - v2;
    }

    protected void swap(int i1, int i2) {
        swapCount++;
        int tmp = array[i1];
        array[i1] = array[i2];
        array[i2] = tmp;
    }
}
